home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Src / structs.h < prev    next >
C/C++ Source or Header  |  1993-07-12  |  12KB  |  491 lines

  1. /* ******************************************************************** */
  2. /*  structs.h        Copyright (C) Codemist and University of Bath 1989 */
  3. /*                                                                      */
  4. /* Basic definitions of tags and structures                             */
  5. /* ******************************************************************** */
  6.  
  7. /*
  8.  * Change Log:
  9.  *   Version 1, April 1989
  10.  *   added a little support for classes RJB
  11.  *   hacked it about a bit KJP
  12.  *   added semaphores KJP
  13.  */
  14.  
  15. #ifndef STRUCTS_H
  16. #define STRUCTS_H
  17.  
  18. #include <stdio.h>
  19.  
  20. #ifdef WITH_BIGNUMS
  21. #include "BigZ.h"
  22. #endif
  23. #undef BIGNUM
  24.  
  25. #ifndef SETJMP_H
  26. #define SETJMP_H
  27. #include <setjmp.h>
  28. #endif
  29.  
  30. /* Load system types... */
  31.  
  32. #include "system_t.h"
  33.  
  34. /*#include "compact.h"*/
  35. /* Primitive types... */
  36.  
  37. /* indiacte that ob can be swept */
  38.  
  39. #define CALLABLE_TYPE 0x80
  40. #define STATIC_TYPE   0x40
  41.  
  42. #define TYPE_UNUSED     -1
  43.  
  44. #define TYPE_ENV    0x30
  45. #define TYPE_FIXENV     0x31
  46. #define TYPE_MBIND    0x32 /* Not really envs, but close enough */
  47. #define TYPE_FIXMBIND  0x33
  48. #define TYPE_EXP_MBIND 0x34
  49. #define TYPE_EXP_FIXMBIND 0x35
  50.  
  51.  
  52. #define TYPE_CONS    0x1
  53. #define TYPE_CHAR    (0x2)
  54. #define TYPE_STRING    (0x3)
  55.  
  56. #define TYPE_SYMBOL     (0x6)
  57. #define TYPE_THREAD    (0xb)
  58. #define TYPE_STREAM    (0xc)
  59. #define TYPE_CLASS    (0xd)
  60. #define TYPE_INSTANCE    (0xe)
  61. #define TYPE_SPECIAL    (0xf)
  62. #define TYPE_VECTOR    0x10
  63.  
  64. #define TYPE_INT    (0x11)
  65. #define TYPE_FLOAT    (0x12)
  66.  
  67. #define TYPE_SEMAPHORE  (0x13)
  68. #define TYPE_LISTENER   (0x14)
  69. #define TYPE_SOCKET     (0x15)
  70. #define TYPE_NULL       (0x16)
  71. #define TYPE_WEAK_WRAPPER 0x17
  72.  
  73. #define TYPE_CONTINUE    (0x18)
  74.  
  75. #define TYPE_C_MODULE   (0x20)
  76. #define TYPE_I_MODULE   (0x21)
  77. #define TYPE_C_FUNCTION (0x22 | CALLABLE_TYPE)
  78. #define TYPE_I_FUNCTION (0x23 | CALLABLE_TYPE)
  79. #define TYPE_GENERIC    (0x24 | CALLABLE_TYPE)
  80. #define TYPE_METHOD     0x25
  81. #define TYPE_SPECIAL_METHOD 0x26
  82.  
  83. #define TYPE_C_MACRO    (0x22 )
  84. #define TYPE_I_MACRO    (0x23 )
  85.  
  86. #define TYPE_B_FUNCTION (0x27 | CALLABLE_TYPE)
  87. #define TYPE_B_MACRO    (0x27)
  88.  
  89. /* Primitive accessors... */
  90. #ifdef NOLOWTAGINTS
  91. #define typeof(p)      ((p)->OBJECT.header.type)
  92. #define classof(p)      ((p)->OBJECT.header.class)
  93. #else
  94. #define typeof(p)       (((int)p) & 1 ? TYPE_INT: ((p)->OBJECT.header.type))
  95. #define classof(p)     (((int)p) & 1 ? Integer: ((p)->OBJECT.header.class))
  96. #endif
  97. #define type_of(p)      typeof(p)
  98. #define gcof(p)         (((p)->OBJECT).header.gc)
  99. #define gc_of(p)        gcof(p)
  100. #define ageof(p)    ((p)->OBJECT.header.age)
  101. #define lval_classof(p)  ((p)->OBJECT.header.class)
  102. #define lval_typeof(p)   ((p)->OBJECT.header.type)
  103.  
  104. #define class_of(p)     classof(p)
  105.  
  106. /* Primitive type testers... */
  107.  
  108. #define is_cons(p)      (typeof(p) == TYPE_CONS)
  109. #define is_char(p)      (typeof(p) == TYPE_CHAR)
  110. #define is_string(p)    ((typeof(p) &0xbf) == TYPE_STRING)
  111. #define is_table(p)     (classof(p) == Table)
  112. #define is_symbol(p)    (typeof(p) == TYPE_SYMBOL)
  113. #define is_function(p)  (typeof(p) & CALLABLE_TYPE)
  114. #define is_macro(p)     (typeof(p) == TYPE_C_MACRO || typeof(p) == TYPE_I_MACRO || typeof(p) == TYPE_B_MACRO)
  115. #define is_static(p)    (typeof(p) & STATIC_TYPE)
  116. #define is_module(p)    ((typeof(p) == TYPE_I_MODULE)  | \
  117.              (typeof(p) == TYPE_C_MODULE))
  118. #define is_special(p)   (typeof(p) == TYPE_SPECIAL)
  119. #define is_thread(p)    (typeof(p) == TYPE_THREAD)
  120. #define is_stream(p)    (typeof(p) == TYPE_STREAM)
  121. #ifdef NOLOWTAGINTS
  122. #define is_fixnum(p)    (typeof(p) == TYPE_INT)
  123. #else
  124. #define is_fixnum(p)    (((int) (p)) &1)
  125. #define mk_fixnum(x)     ((LispObject) (((x)<<1) | 1))
  126. #endif
  127.  
  128. #define is_float(p)     (typeof(p) == TYPE_FLOAT)
  129. #define is_vector(p)    ((typeof(p)&(STATIC_TYPE-1)) == TYPE_VECTOR)
  130. #define is_continue(p)    (typeof(p) == TYPE_CONTINUE)
  131. #define is_env(p)    (typeof(p) == TYPE_ENV || typeof(p)==TYPE_FIXENV)
  132. #define is_bind(x) ( (typeof(x)&0xf0) == TYPE_ENV)
  133.  
  134.  
  135. #define is_c_function(p) (typeof(p) == TYPE_C_FUNCTION)
  136. #define is_c_module(p)  (typeof(p) == TYPE_C_MODULE)
  137. #define is_i_function(p) (typeof(p) == TYPE_I_FUNCTION)
  138. #define is_i_module(p)  (typeof(p) == TYPE_I_MODULE)
  139. #define is_c_macro(p)   (typeof(p) == TYPE_C_MACRO)
  140. #define is_i_macro(p)   (typeof(p) == TYPE_I_MACRO)
  141. #define is_b_function(p) (typeof(p)==TYPE_B_FUNCTION)
  142. #define is_b_macro(p)    (typeof(p) == TYPE_B_MACRO)
  143.  
  144. #define is_semaphore(p) (typeof(p) == TYPE_SEMAPHORE)
  145. #define is_listener(p)  (typeof(p) == TYPE_LISTENER)
  146. #define is_socket(p)    (typeof(p) == TYPE_SOCKET)
  147. #define is_weak_wrapper(p) (typeof(p) == TYPE_WEAK_WRAPPER)
  148.  
  149. #define is_e_function(p) (0)
  150. #define is_e_macro(p) (0)
  151.  
  152. /* Other macros... */
  153.  
  154. #define null(p)      ((LispObject)(p) == nil)
  155. #define consp(p)     (is_cons(p) && (p) != nil)
  156. #define symbolp(p)   (is_symbol(p) || (p) == nil)
  157. #define CAR(p)         (((p)->CONS).car)
  158. #define CDR(p)         (((p)->CONS).cdr)
  159.  
  160.  
  161. typedef union lispunion *LispObject;
  162.  
  163. typedef struct Object_struct
  164. {
  165.   short type;
  166.   char gc;
  167.   unsigned char age;
  168.   LispObject class;
  169. } Object_t;
  170.  
  171. struct env_structure {
  172.   Object_t    header;
  173.   LispObject    variable;
  174.   LispObject    value;
  175.   LispObject     next;
  176. };
  177.  
  178. /* the top most class object */
  179.  
  180. struct object_structure {
  181.   Object_t    header;
  182.   LispObject    slots[1];    /* the other slots */
  183. };
  184.  
  185.  
  186. struct integer_structure {
  187.   Object_t     header;
  188.   int        value_part;
  189. };
  190. #ifdef NOLOWTAGINTS
  191. #define intval(x) ((x)->INT.value_part)
  192. #else
  193. #define intval(x) (((int)x)>>1)
  194. #endif
  195.  
  196. /* low tag ints */
  197.  
  198.  
  199.  
  200. struct float_structure {
  201.   Object_t     header;
  202.   double    fvalue;
  203. };
  204.  
  205.  
  206. struct character_structure {
  207.   Object_t header; 
  208.   short font;
  209.   short code;
  210. };
  211.  
  212. struct symbol_structure {
  213.   Object_t    header;
  214.   int         hash;      /* hash value cache */
  215.   LispObject    lmodule;  /* Module lookup cache for the interpreter */
  216.   LispObject    lvalue;   /* Part II */
  217.   LispObject    gvalue;   /* Dynamic global value */
  218.   LispObject    pname;
  219.  
  220.   LispObject left;
  221.   LispObject right;
  222. };
  223.  
  224. #define vref(v,n) (&((v)->VECTOR.base))[n]
  225. #define vrefupdate(v,n,obj) (vref(v,n)=(obj))
  226. #define vector_length(x) ((x)->VECTOR.length)
  227.  
  228. struct vector_structure {
  229.   Object_t header;
  230.   int length;            /* for now */
  231.   LispObject base;           
  232. };
  233.  
  234. #ifdef WITH_SMALL_CONSES
  235. struct cons_structure {
  236.   short        type;
  237.   short        gc;
  238.   LispObject    car;
  239.   LispObject    cdr;
  240. };
  241. #else
  242. struct cons_structure {
  243.   Object_t header;
  244.   LispObject    car;
  245.   LispObject    cdr;
  246. };
  247. #endif
  248.  
  249. struct string_structure {
  250.   Object_t header;
  251.   int length;
  252.   char value; /* really a c-string --- Should these be CHARs ?? */
  253. };
  254.  
  255. #define stringof(x)\
  256.   (&((x)->STRING.value))
  257.  
  258. struct continue_structure {
  259.   Object_t header;
  260.  
  261.   LispObject  *gc_stack_pointer; /* Interpreter state */
  262.   /* Bytecode state? */
  263.  
  264.   jmp_buf       machine_state;
  265.  
  266.   int           live;
  267.   int           unwind;
  268.   LispObject    value;     /* Returned with... */
  269.   LispObject    target;    /* When bouncing unwind protects... */
  270.  
  271.   LispObject    thread;
  272.  
  273.   LispObject    dynamic_env;
  274.   LispObject    last_continue;
  275.   LispObject    handler_stack;
  276.  
  277.   LispObject    dp;  /* Elvira state */
  278. };
  279.  
  280. typedef struct thread_data {
  281.   LispObject *gc_stack_base;
  282.   short signalled;
  283.   short status;
  284.   int stack_size;
  285.   int gc_stack_size;
  286.   int *stack_base;
  287. } *ThreadData;
  288.  
  289. struct thread_structure {
  290.   Object_t header;
  291.   
  292.   LispObject     sysdata; /* pointer to thread data */
  293.   LispObject     state;
  294.  
  295.   LispObject    fun;
  296.   LispObject    args;
  297.   LispObject    value;
  298.  
  299.   LispObject    thd_queue;
  300.   LispObject     sig_queue;
  301. };
  302.  
  303. struct semaphore_structure {
  304.   Object_t header;
  305.   SystemSemaphore semaphore; /* Just a hacked wrapper */
  306. };
  307.  
  308. struct class_structure {
  309.   Object_t header;
  310.   LispObject    local_count;   /* Number of local slots */
  311.   LispObject    name;           /* Name of the class (NOT binding name) */
  312.   LispObject    superclasses;  /* Direct parents */
  313.   LispObject    subclasses;    /* Direct subclasses */
  314.   LispObject    local_slot_list;    /* local slot descriptions (fed to init-structure) */
  315.   LispObject    slot_list;     /* Slot list */
  316.   LispObject    nonlocal_slot_list; /* non-local sds slot list */
  317.   LispObject    precedence;    /* Class precedence list */
  318.   LispObject    spare1;
  319.   LispObject     spare2;
  320. };
  321.  
  322. #define slotref(v,n)  ((&((v)->INSTANCE.slots))[n])
  323. #define slotrefupdate(v,n,obj) (slotref(v,n)=obj)
  324.  
  325. struct instance_structure {
  326.   Object_t    header;
  327.   LispObject    slots;        /* Some structure of data */
  328. };
  329.  
  330.  
  331. /* Functions... */
  332.  
  333. /* Special forms are compiler only and don't have homes (?) */
  334.  
  335. struct special_structure {
  336.   Object_t header;
  337.   LispObject    (*func)();
  338.   LispObject    name;
  339.   LispObject    env;
  340. };
  341.  
  342. /* Basic function template to which all conform */
  343.  
  344. struct function_structure {
  345.   Object_t     header;
  346.   int        argtype;   /* Argument type code - unique for args */
  347.   LispObject    env;       /* Defining parameter environment */
  348.   LispObject    gunk;       /* either func or bvl */
  349.   LispObject    name;      /* Original name in their module of origin */
  350.   LispObject    home;      /* Module of origin */
  351.  
  352. };
  353.  
  354. struct c_function_structure {
  355.   Object_t      header;
  356.   int         argtype;
  357.   LispObject  (*func)();   /* Compiled functions just need fun pointer */
  358.   LispObject  env;
  359.   LispObject  name;
  360.   LispObject  home;
  361.  
  362.   LispObject setter;
  363. };
  364.  
  365. struct i_function_structure {
  366.   Object_t    header;
  367.   int        argtype;    
  368.   LispObject    env;
  369.   LispObject    bvl;        /* Parameter list */
  370.   LispObject    name;
  371.   LispObject    home;  
  372.  
  373.   LispObject    body;           /* Body forms */
  374. };
  375.  
  376. /* Macros are a logical entity - being just specially interpretted functions */
  377.  
  378. /* Module structures */
  379.  
  380. /* Template for all types - an abstract class like function */
  381.  
  382. struct module_structure {
  383.   Object_t      header;
  384.   LispObject  name;              /* Symbol */
  385.   LispObject  home;              /* In ? */
  386.   LispObject  imported_modules;  /* Module dependecies - name list */
  387.   LispObject  exported_names;    /* Name list too */
  388.   LispObject  bindings;
  389. };
  390.  
  391. struct c_module_structure {
  392.   Object_t    header;
  393.   LispObject  name;
  394.   LispObject  home;
  395.   LispObject  imported_modules;
  396.   LispObject  exported_names;
  397.   LispObject  bindings;
  398.   
  399.   LispObject  values;            /* Value vector of static module */
  400.   LispObject  entry_count;
  401. };
  402.  
  403. typedef struct c_module_structure MODULE;
  404.  
  405. struct i_module_structure {
  406.   Object_t     header;
  407.   LispObject   name;
  408.   LispObject   home;
  409.   LispObject   imported_modules;      
  410.   LispObject   exported_names;        
  411.   LispObject   bindings;
  412.  
  413.   LispObject   bounce_flag;
  414. };
  415.  
  416. /* Sockets support... */
  417.  
  418. #if (defined(WITH_BSD_SOCKETS) || defined(WITH_SYSTEMV_SOCKETS))
  419.  
  420. #include "syssockets.h"
  421.  
  422. struct listener_structure {
  423.   Object_t header;
  424.   
  425.   SocketHandle   socket;
  426.   SocketInName   name;
  427.  
  428.   int            state;
  429. };
  430.  
  431. struct socket_structure {
  432.   Object_t      header;
  433.  
  434.   SocketHandle   socket;
  435.   SocketInName   name;
  436.  
  437.   char           buffer[SOCKET_BUFFER_SIZE]; /* Input buffer */
  438.  
  439.   int            state;
  440.   int          lastchar;
  441. };
  442.  
  443. #endif
  444.  
  445. /* Weak wrappers... */
  446.  
  447. struct weak_wrapper_structure {
  448.   Object_t header;
  449.   LispObject  object;
  450. };
  451.  
  452. union lispunion {
  453.   struct object_structure    OBJECT;
  454.   struct integer_structure    INT;
  455.   struct float_structure    FLOAT;
  456.   struct character_structure    CHAR;
  457.   struct symbol_structure    SYMBOL;
  458.   struct cons_structure        CONS;
  459.   struct string_structure       STRING;
  460.   struct thread_structure       THREAD;
  461.   struct semaphore_structure    SEMAPHORE;
  462.   struct class_structure    CLASS;
  463.   struct instance_structure    INSTANCE;
  464.   struct vector_structure       VECTOR;
  465.   struct continue_structure    CONTINUE;
  466.   struct env_structure        ENV;
  467.   struct special_structure      SPECIAL;
  468.   struct function_structure     FUNCTION;
  469.   struct c_function_structure   C_FUNCTION;
  470.   struct i_function_structure   I_FUNCTION;
  471. /**  struct generic_structure      GENERIC; */
  472.   struct function_structure     MACRO;
  473.   struct c_function_structure   C_MACRO;
  474.   struct i_function_structure   I_MACRO;
  475. /**   struct method_structure       METHOD; */
  476.   struct module_structure       MODULE;
  477.   struct c_module_structure     C_MODULE;
  478.   struct i_module_structure     I_MODULE;
  479. #if (defined(WITH_BSD_SOCKETS) || defined(WITH_SYSTEMV_SOCKETS))
  480.   struct listener_structure     LISTENER;
  481.   struct socket_structure       SOCKET;
  482. #endif 
  483.   struct weak_wrapper_structure WEAK_WRAPPER;
  484. };
  485.  
  486. #include "system_p.h"
  487.  
  488. #endif /* STRUCTS_H */
  489.  
  490. /* End of structs.h */
  491.